package Main;

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.Scanner;

import com.mysql.jdbc.Statement;


public class Menu{                                 //界面以及可购买商品信息
	String url = "jdbc:mysql://localhost:3306/goods";
    String userName = "root";
    String password = "kamisama";
    String driverName = "com.mysql.jdbc.Driver";
    String strSql = "select * from good";
    Scanner sc = new Scanner(System.in);
    	Connection con = null;
    	Statement pstmt = null;
    	ResultSet rs = null;
    	String driverName1 = "com.mysql.jdbc.Driver";
	public void Menu(){
		try {
			Class.forName(driverName);
	        con = (Connection) DriverManager.getConnection(url, userName, password);
	        pstmt = (Statement) con.createStatement();
	        rs = pstmt.executeQuery(strSql);
	        while (rs.next()) {
	            int id = rs.getInt("id");
	            String name = rs.getString("name");
	            Double price = rs.getDouble("price");
	            int num = rs.getInt("num");
	            String description = rs.getString("description");
	            System.out.print("id=" + id + "  name="+name+ " price="+price+"  num=" + num+" description="+description+"\n");
	        }
		} catch (ClassNotFoundException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}catch (SQLException e){
			e.printStackTrace();
		}finally {
            if (rs != null)
                try {
                    rs.close();
                } catch (Exception e) {
                    e.printStackTrace();
                }
            if (pstmt != null){
                try {
                    pstmt.close();// 关闭语句
                } catch (Exception e) {
                    e.printStackTrace();
                }
            }
            if (con != null) {
                try {
                    con.close();// 关闭连接
                } catch (Exception e) {
                    e.printStackTrace();
                }
            }
        }
		/*System.out.println("|*******************************************************************|");
		System.out.println("|**************************##购物系统##***************************|");
		System.out.println("|***************************1.购买商品******************************|");
		System.out.println("|***************************2.查看购物车****************************|");
		System.out.println("|***************************3.删除商品******************************|");
		System.out.println("|***************************4.修改数量******************************|");
		System.out.println("|***************************5.商家系统******************************|");
		System.out.println("|***************************6.结账**********************************|");
		System.out.println("|*******************************************************************|");
		System.out.println("请选择:");
		GetGoods g = new GetGoods();
		SelectCarGoods s = new SelectCarGoods();
		DeleteCarGoods d = new DeleteCarGoods();
		UpdataNum u = new UpdataNum();
		Business b = new Business();
		AddCarGoods c = new AddCarGoods();
		String a = sc.next();
			if(a.equals("1"))
				g.Getgoods();
			if(a.equals("2"))
				c.Addcargoods();
			if(a.equals("3"))
				d.DeleteCargoods();
			if(a.equals("4"))
				u.updata();
			if(a.equals("5"))
				b.bussiness();*/
    }
}

